# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

pkgname=lftp
pkgver=4.6.4
pkgrel=1
pkgdesc="Sophisticated command line based FTP client (net-utils)"
arch=('i686' 'x86_64')
license=('GPL3')
groups=('net-utils')
depends=('gcc-libs'
         'ca-certificates'
         'expat'
         'gettext'
         'libexpat'
         'libgnutls'
         'libiconv'
         'libidn'
         'libintl'
         'libhogweed'
         'libnettle'
         'libp11-kit'
         'libreadline'
         'libtasn1'
         'openssh'
         'zlib')
makedepends=('gcc'
             'gettext-devel'
             'libexpat-devel'
             'libgnutls-devel'
             'libiconv-devel'
             'libidn-devel'
             'libnettle-devel'
             'libp11-kit-devel'
             'libreadline-devel'
             'libtasn1-devel'
             'zlib-devel')
optdepends=('perl: needed for convert-netscape-cookies and verify-file')
url="http://lftp.yar.ru/"
backup=('etc/lftp.conf')
source=(http://lftp.yar.ru/ftp/${pkgname}-${pkgver}.tar.xz{,.asc}
        lftp-4.4.15-msysize.patch
        lftp-4.4.15-no-undefined.patch)
options=('debug' '!strip')
md5sums=('84987c1095df84bfb5ac9c95c6aba6be'
         'SKIP'
         '9b34d1d402d804cf3660d8a9fd0c00a4'
         '70767b69404fdd0b8d6c7f185f3b5b3b')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/lftp-4.4.15-msysize.patch
  patch -p1 -i ${srcdir}/lftp-4.4.15-no-undefined.patch

  #autoreconf -fi
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${pkgname}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --with-gnutls \
    --without-openssl \
    --without-included-regex \
    --disable-rpath \
    --disable-static \
    --with-debug
  make
}

check() {
  cd ${srcdir}/build-${CARCH}
  make -k check
}

package() {

  cd ${srcdir}/build-${CARCH}
  make DESTDIR=${pkgdir} install
  
  grep -q 'set ssl:ca-file' ${pkgdir}/etc/lftp.conf || echo 'set ssl:ca-file /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem' >> ${pkgdir}/etc/lftp.conf

}
